package com.estudos.dao;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Autowired;


public class DAO {
	@Autowired
	protected EntityManager em;
	protected Query query;
	protected StringBuilder sql;
	
	
	public void begin(){
		if(em.isOpen()){
			if(!em.getTransaction().isActive()){
				em.getTransaction().begin();
			}
		}
	}
	
	public void commit(){
		if(em.getTransaction().isActive()){
			em.getTransaction().commit();
		}
	}
	
	public void fechar(){
		if(em.isOpen()){
			if(em.getTransaction().isActive()){
				em.getTransaction().commit();
			}
			em.close();
		}
	}
	
	public void rollBack(){
		if(em.isOpen()){
			if(em.getTransaction().isActive()){
				em.getTransaction().rollback();
			}
			em.close();
		}
	}
	
}
